clear; clc;

videoname = 'bootstrap.mat';

load(strcat('data/video/',videoname));

data = double(data);
data = data/255;
[m, n, k] = size(data);
data = reshape(data, m*n, k);

colMean = mean(data, 1);
data = bsxfun(@minus, data, colMean);

O = data + 0.15*randn(size(data));
colMean = mean(O, 1);
O = bsxfun(@minus, O, colMean);

PSNRin = psnr(O, data, 1);

tstIdx = ceil(k*rand(ceil(k/2), 1));

O = O(:,tstIdx);

clear colMean m n k idx;

para.tol = 1e-2;
para.tau = 1.01;
para.maxIter = 100;
para.decay = 0.3;
para.test = data(:, tstIdx);

clear data;

%% APG
lambda = 50;
mu = lambda/sqrt(max(size(O)));
t = tic;
[ X, Y, out{1} ] = APGRPCA(O, lambda, mu, para);
Time(1) = toc(t);
PSNR(1) = out{1}.PSNR(end);

clear X Y D lambda mu;

for regType = 2:4
    para.regType = regType - 1;
    theta2 = 1e+6;

    switch(para.regType)
        case 1
            lambda = [41.9255043682763];
            theta1 = lambda*1.25;
            mu = lambda/sqrt(max(size(O)));
        case 2
            lambda = 2100;
            theta1 = sqrt(lambda);
            mu = 41.92/sqrt(max(size(O)));
        case 3
            lambda = [41.9869720590061];
            theta1 = 50;
            mu = lambda/sqrt(max(size(O)));
    end

    t = tic;
    [ X, Y, out{1,regType} ] = FastProxRPCA( O, lambda, mu, theta1, theta2, para);
    Time(2,regType) = toc(t);
    PSNR(2,regType) = out{1,regType}.PSNR(end);

    clear X Y D;

    %% GIST
    t = tic;
    [ X, Y, out{2,regType} ] = GISTRPCA( O, lambda, mu, theta1, theta2, para);
    Time(3,regType) = toc(t);
    PSNR(3,regType) = out{2,regType}.PSNR(end);

    clear X Y D;

    save('temp', 'out', 'PSNR', 'Time');
end

clear lambda mu O para regType t theta1 theta2 tstIdx;

save('bootstrap-dn3');
